import { mpRequest } from "@/utils/request";
import { IGoodsListReq } from "./types/jifen";
import { IPage } from "./types";

/**
 * 获取推荐商品
 */
export const apiQueryGoodsRecommend = () => {
  return mpRequest({
    url: "/points/goods/recommend",
    method: "GET",
  });
};

/**
 * 获取商品列表
 */
export const apiQueryGoodsList = (params: IGoodsListReq) => {
  return mpRequest({
    url: "/points/goods/list",
    method: "GET",
    params,
  });
};

/**
 * 获取用户积分
 */
export const apiQuerySelfPoints = () => {
  return mpRequest({
    url: "/points/self",
    method: "GET",
  });
};

/**
 * 获取积分记录
 */
export const apiQueryselfPointsList = (params: IPage) => {
  return mpRequest({
    url: "/points/self/list",
    method: "get",
    params,
  });
};

/**
 * 获取兑换记录
 */
export const apiQueryPointsExchangeList = (params: IPage) => {
  return mpRequest({
    url: "/points/list/exchange",
    method: "get",
    params,
  });
};

/**
 * 获取积分排名
 */
export const apiQueryselfPointsRank = (params: IPage) => {
  return mpRequest({
    url: "/points/rank",
    method: "get",
    params,
  });
};

/**
 * 校验用户是否有足够的积分可兑换
 */
export const apiCheckExchangeById = (id: number) => {
  return mpRequest({
    url: `/points/exchange/check/${id}`,
    method: "get",
  });
};

/**
 * 兑换商品
 */
export const apiExchangeGoods = (id: number) => {
  return mpRequest({
    url: `/points/exchange/${id}`,
    method: "get",
  });
};

/**
 * 获取过去7天的积分历史积分
 */
export const apiQueryPointsHistory = () => {
  return mpRequest({
    url: "/points/history",
    method: "get",
  });
};
